class BaiViet
  include MongoMapper::Document
  before_save :xac_dinh_mac_dinh

  key     :slug,              String,   :presence => true,    :length => {:minimum => 4}, :uniqueness => true
  key     :ngon_ngu,          String,   :presence => true,    :length => {:minimum => 2}
  key     :tieu_de,           String,   :presence => true,    :length => {:minimum => 10}
  key     :noi_dung,          String
  key     :meta_description,   String
  key     :dang_kich_hoat,    Boolean
  
  def xac_dinh_mac_dinh
    if self.dang_kich_hoat.nil?
    self.dang_kich_hoat = true;
    end
  end

  timestamps!

  belongs_to  :danh_muc
  belongs_to  :nguoi_dung
end
